//导入相关模块
import {Interval} from "../../../../gcg/libs/timer/Interval.js";//任务管理器
import {Role} from "../../../../gcg/libs/role/role/Role.js";//角色组件
import {Crash} from "../../../../gcg/libs/crash/Crash.js";//碰撞组件
import {CompeteConstant} from "../../../../gcg/libs/constants/CompeteConstant.js";
import {Foe} from "../../../../gcg/libs/foe/foe/Foe.js";
import {Log} from "../../../../gcg/libs/log/Log.js";
import {Container} from "../../../../gcg/libs/container/Container.js";
import {FoeSquare} from "./FoeSquare.js";
import {Move} from "../../../../gcg/libs/role/body/Move.js";
import {FriendSquare} from "./FriendSquare.js";
import {Fire} from "../../../../gcg/libs/fire/Fire.js";
//移动组件


//运行多个敌人,敌人自由移动，自由停止

!function () {
    //友军
    let roleElement = $('#role');
    (new FriendSquare()).init(roleElement);


    //设置fire
    let fireElement = $('.fire');
    let fire = new Fire(roleElement, fireElement);
    //检查属性
    fire.noumenonCheck();
    //设置初始位置
    fire.follow();


    //敌军
    let foe = (new FoeSquare()).init();


    //初始化移动组件
    let move = new Move();



    //初始化碰撞检测组件
    let crash = new Crash();
    crash.init();




    let timeArr = [
        33,
        39,
        32
    ];
    // 方块自由移动
    $(foe.getClass()).each(function (a, foeElement) {
        //初始化任务管理器
        let interval = new Interval();
        interval.time = timeArr[a];

        //初始化移动组件
        move.init(foeElement);

        let freeItv = interval.set(function () {
            try{
                //方块移动
                move.do(foeElement);
                //实时碰撞检测
                crash.mathCrash(roleElement, foeElement, function () {
                    interval.stop(freeItv);
                });

                //边界碰撞检测
                crash.detectContainer(foeElement,function () {
                    interval.stop(freeItv);
                });


            }catch (e) {
                Log.log(e);
                interval.stop(freeItv);
            }

        });
    });


    //控制友方单位本体移动
    // $(function () {
        //键盘按下
        // $('body').bind('keydown', function (e) {
        //     var key = e.keyCode;
        //     // console.log(key);
        //     if(key == 87){
        //         //上
        //         up();
        //     }else if(key == 83){
        //         //下
        //         down();
        //     }else if(key == 65){
        //         //左
        //         left();
        //     }else if(key == 68){
        //         //右
        //         right();
        //     }
        // });
        // //发射一颗fire
        // $('body').bind('keyup', function (e) {
        //     if(!fire_close)return;//子弹开关
        //     var key = e.keyCode;
        //
        //     if(key == 74){
        //         fire();
        //     }
        // })
    // });
}();